package com.zgh.leo.signin611;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class DrawerActivity extends BaseActivity {
    private Toolbar toolbar;
    private ListView listView;
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle actionBarDrawerToggle;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drawer);
        toolbar=findViewById(R.id.toolbar);
        toolbar.setSubtitle("");
        toolbar.setTitle("");
        listView=findViewById(R.id.listview);
        toolbar.setNavigationIcon(R.drawable.plus);
        setSupportActionBar(toolbar);
        drawerLayout=findViewById(R.id.drawer_layout);
        actionBarDrawerToggle=new ActionBarDrawerToggle(this,drawerLayout,0,0);
        actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
        drawerLayout.addDrawerListener(actionBarDrawerToggle);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.openDrawer(Gravity.START);
            }
        });


        List<Model> list=new ArrayList<>();
        for (int i=0;i<5;i++) {
            Model model=new Model("列表项",R.drawable.ic_head);
            list.add(model);
        }



        listView.setAdapter(new ListViewAdapter(this,list));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                drawerLayout.closeDrawers();
            }
        });

    }
    class Model{
        String content;
//        int index;
        int id;

        public Model(String content, int id) {
            this.content = content;
            this.id = id;
        }
    }


    class ListViewAdapter extends BaseAdapter{


        List<Model> list;
        Context context;

        public ListViewAdapter(Context context,List<Model> list) {
            this.context=context;
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Model getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view=View.inflate(context,R.layout.listvivew_item,null);
            ImageView imageView=view.findViewById(R.id.imageView);
            TextView textView=view.findViewById(R.id.content);
            imageView.setImageResource(list.get(position).id);
            textView.setText(list.get(position).content);
            return view;
        }
    }

}
